package com.jiang.filter;


import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author jiangjingbo
 * @version V1.0
 * @Project java2203
 * @Package com.jiang.filter
 * @Description:
 * @Date 2022/5/21 16:14
 */
@WebFilter("/*")
public class EncodingFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //解决请求的字节码
        servletRequest.setCharacterEncoding("utf-8");
        //解决响应的字节码
        servletResponse.setCharacterEncoding("utf-8");
        servletResponse.setContentType("text.html;charset=utf-8");
        //请求放行
        filterChain.doFilter(servletRequest,servletResponse);
    }
    @Override
    public void destroy() {

    }
}
